/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-07 09:26:03
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-29 13:17:05
 * @FilePath: /yt-devops/lib/pages/amap/amap_view.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xbr_gaode_amap/base/amap_flutter_base.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/model/amap_poi.dart';
import 'package:yt_devops/pages/amap/widget/amap_widget.dart';
import 'package:yt_devops/pages/amap/widget/google_map_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import '../../styles/styles.dart';
import 'map_controller.dart';
import 'package:google_maps_flutter_platform_interface/src/types/location.dart'
    as GoogleLatng;

// import 'package:amap_flutter_location/amap_flutter_location.dart';
// import 'package:amap_flutter_location/amap_location_option.dart';

class MapPage extends GetView<AmapPageController> {
  MapPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AmapPageController>(
      builder: (controller) => ConstrainedBox(
        constraints: const BoxConstraints.expand(),
        child: Stack(
          alignment: Alignment.center,
          children: [
            SizedBox(
                height: MediaQuery.of(context).size.height,
                width: MediaQuery.of(context).size.width,
                child: controller.mapType == 0
                    ? (controller.initLocation == null ?Container():AmapWidget(
                        key: controller.amapKey,
                        position: controller.initLocation ??
                            const LatLng(39.909187, 116.397451),
                        onPositionShow: (AmapPoi poi) =>
                            controller.onPoiTouched(context, poi),
                      ))
                    : (controller.initLocation == null ?Container():GoogleMapWidget(
                        key: controller.googlemapKey,
                        position: controller.initLocation != null
                            ? GoogleLatng.LatLng(
                                controller.initLocation!.latitude,
                                controller.initLocation!.longitude)
                            : const GoogleLatng.LatLng(39.909187, 116.397451),
                        onPositionShow: (AmapPoi poi) =>
                            controller.onPoiTouched(context, poi),
                      ))),
            Positioned(
                top: 0,
                left: 0,
                right: 0,
                child: SizedBox(
                  height: 200,
                  child: Scaffold(
                    resizeToAvoidBottomInset: false,
                    backgroundColor: Colors.transparent,
                    appBar: AppBarWidget.defaultAppBar(ResKey.siteAddress.tr,
                        backgroundColor: Colors.transparent),
                    body: BrnSearchText(
                      maxHeight: 58.h,
                      innerPadding: EdgeInsets.only(
                          top: 8.h, bottom: 8.h, left: 20.w, right: 20.w),
                      outSideColor: Colors.transparent,
                      innerColor: Colors.white,
                      controller: controller.textController,
                      hintText: ResKey.enterDetailAddress.tr,
                      textInputAction: TextInputAction.search,
                      onTextCommit: (String text) =>
                          controller.searchAroundAddress(context, text),
                    ),
                  ),
                )),
          ],
        ),
      ),
    );
  }
}
